//
// Created by Zsir on 2025/7/25.
//

#ifndef THREAD_THREADPOOL_H
#define THREAD_THREADPOOL_H

#include "Task.h"
#include "Thread.h"
#include "vector"
#include "memory"
#include "deque"
#include "functional"

class threadPool
{
public:
    using Func = std::function<void(void *)>;

    explicit threadPool(int threadNum);

    ~threadPool();

    Task getTask();

    void addTask(Func func, void *data);

    void shutDown();

private:
    pthread_mutex_t mutex_{};
    pthread_cond_t cond_{};

    bool shutdown_;

    std::deque<std::unique_ptr<Task>> tasks_; // 使用deque实现FIFO
    std::vector<std::unique_ptr<Thread>> threads_;
};


#endif //THREAD_THREADPOOL_H
